﻿<controls:MetroWindow x:Class="Restaurant.Reservations.View.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                      xmlns:userControls="clr-namespace:Restaurant.Reservations.UserControls"
                      x:Name="MetroWindow"
                      Title="Reservation System"
                      Width="750"
                      Height="600"
                      MinWidth="725"
                      MinHeight="550"
                      MaxWidth="1000"
                      MaxHeight="700"
                      BorderBrush="Black"
                      BorderThickness="1"
                      Icon="{StaticResource AppIcon}"
                      ShowMaxRestoreButton="False"
                      ShowMinButton="False"
                      WindowStartupLocation="CenterScreen"
                      WindowStyle="ToolWindow">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Grid.Column="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" MinWidth="500" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>


            <GroupBox Grid.Row="0"
                      Grid.Column="0"
                      Margin="5"
                      Header="Today's Reservations:">
                <DataGrid Margin="5"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Top"
                          AutoGenerateColumns="False"
                          ItemsSource="{Binding TodayReservations}"
                          SelectedItem="{Binding SelectedReservation}">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Width="*" Header="Customer">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Left" Text="{Binding CustomerName}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="120"
                                                Header="Contact">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding ContactNumber}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="100"
                                                Header="Occupants">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding Occupants}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="60"
                                                Header="Table">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding SelectedTableString}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="150"
                                                Header="Check-in">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center"
                                               Background="{Binding IsDelayed,
                                                                    Converter={StaticResource BoolToBrushConverter}}"
                                               Text="{Binding CheckInDate,
                                                              StringFormat='{}{0:h:mm tt}'}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </GroupBox>
            <Rectangle Grid.Row="0"
                       Grid.RowSpan="4"
                       Grid.Column="1"
                       Width="1"
                       Margin="2"
                       VerticalAlignment="Stretch"
                       Stroke="Black" />
            <Border Grid.Row="0"
                    Grid.RowSpan="4"
                    Grid.Column="2"
                    BorderBrush="Gray"
                    BorderThickness="1" />
            <Grid Grid.Row="0"
                  Grid.RowSpan="4"
                  Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Border Grid.Row="0"
                        Background="LightGray"
                        BorderBrush="Gray"
                        BorderThickness="1">
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Text="Reservations" />
                </Border>
                <Button Grid.Row="1"
                        Width="80"
                        Height="60"
                        Margin="5"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Background="LightGreen"
                        Command="{Binding CreateNewReservationCommand}"
                        Content="New">
                    <Button.ToolTip>
                        <ToolTip Content="Press to add new reservation." Style="{StaticResource GenericToolTipStyle}" />
                    </Button.ToolTip>
                </Button>
                <Button Grid.Row="2"
                        Width="80"
                        Margin="5,0,5,5"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Background="OrangeRed"
                        Command="{Binding DeleteReservationCommand}"
                        Content="Delete">
                    <Button.ToolTip>
                        <ToolTip Content="Press to delete selected reservation."
                                 Style="{StaticResource GenericToolTipStyle}" />
                    </Button.ToolTip>
                </Button>
                <Button Grid.Row="3"
                        Width="80"
                        Margin="5,0,5,5"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top"
                        Background="LightSkyBlue"
                        Command="{Binding UpdateReservationCommand}"
                        Content="Update">
                    <Button.ToolTip>
                        <ToolTip Content="Press to update selected reservation."
                                 Style="{StaticResource GenericToolTipStyle}" />
                    </Button.ToolTip>
                </Button>
                <Button Grid.Row="3"
                        Width="80"
                        Margin="5,0,5,5"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Bottom"
                        Background="DarkKhaki"
                        Command="{Binding RefreshReservationCommand}"
                        Content="Refresh">
                    <Button.ToolTip>
                        <ToolTip Content="Press to reload all reservations."
                                 Style="{StaticResource GenericToolTipStyle}" />
                    </Button.ToolTip>
                </Button>
                <Border Grid.Row="4"
                        Background="LightGray"
                        BorderBrush="Gray"
                        BorderThickness="1">
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Text="Summary" />
                </Border>
                <Grid Grid.Row="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0"
                               Grid.Column="0"
                               Margin="5"
                               Text="Today" />
                    <TextBlock Grid.Row="0"
                               Grid.Column="1"
                               Margin="0,5,5,5"
                               Text=":" />
                    <TextBlock Grid.Row="0"
                               Grid.Column="2"
                               Margin="0,5,0,5"
                               FontWeight="Bold"
                               Text="{Binding CurrentReservationCount}" />
                    <TextBlock Grid.Row="1"
                               Grid.Column="0"
                               Margin="5"
                               Text="Future" />
                    <TextBlock Grid.Row="1"
                               Grid.Column="1"
                               Margin="0,5,5,5"
                               Text=":" />
                    <TextBlock Grid.Row="1"
                               Grid.Column="2"
                               Margin="0,5,0,5"
                               FontWeight="Bold"
                               Text="{Binding FutureReservationCount}" />
                </Grid>
                <Border Grid.Row="6"
                        Background="LightGray"
                        BorderBrush="Gray"
                        BorderThickness="1">
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Text="Tables" />
                </Border>
                <Grid Grid.Row="7">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0"
                               Grid.Column="0"
                               Margin="5"
                               Text="Used" />
                    <TextBlock Grid.Row="0"
                               Grid.Column="1"
                               Margin="0,5,5,5"
                               Text=":" />
                    <TextBlock Grid.Row="0"
                               Grid.Column="2"
                               Margin="0,5,0,5"
                               FontWeight="Bold"
                               Text="{Binding UsedTablesCount}" />
                    <TextBlock Grid.Row="1"
                               Grid.Column="0"
                               Margin="5"
                               Text="Available" />
                    <TextBlock Grid.Row="1"
                               Grid.Column="1"
                               Margin="0,5,5,5"
                               Text=":" />
                    <TextBlock Grid.Row="1"
                               Grid.Column="2"
                               Margin="0,5,0,5"
                               FontWeight="Bold"
                               Text="{Binding AvailableTablesCount}" />
                </Grid>
                <Separator Grid.Row="8"
                           Grid.Column="0"
                           VerticalAlignment="Bottom" />
                <Button Grid.Row="9"
                        Grid.Column="0"
                        Margin="5,2,5,5"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="Bisque"
                        Command="{Binding SettingsCommand}"
                        Content="Settings">
                    <Button.ToolTip>
                        <ToolTip Content="Press to change application settings."
                                 Style="{StaticResource GenericToolTipStyle}" />
                    </Button.ToolTip>
                </Button>

            </Grid>
            <Separator Grid.Row="1"
                       Grid.Column="0"
                       Margin="0,5,0,0"
                       HorizontalAlignment="Stretch" />
            <GroupBox Grid.Row="2"
                      Grid.Column="0"
                      Margin="5"
                      Header="Future Reservations:">

                <DataGrid Margin="5"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Top"
                          AutoGenerateColumns="False"
                          ItemsSource="{Binding FutureReservations}"
                          SelectedItem="{Binding SelectedReservation}">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Width="*" Header="Customer">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Left" Text="{Binding CustomerName}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="120"
                                                Header="Contact">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding ContactNumber}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="100"
                                                Header="Occupants">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding Occupants}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="60"
                                                Header="Table">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding SelectedTableString}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Width="Auto"
                                                MinWidth="150"
                                                Header="Check-in">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center"
                                               Text="{Binding CheckInDate, StringFormat='{}{0:dd-MMM-yyyy h:mm tt}'}">
                                        <TextBlock.ToolTip>
                                            <ToolTip Style="{StaticResource ReservationToolTipStyle}" />
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

                    </DataGrid.Columns>
                </DataGrid>
            </GroupBox>
            <Separator Grid.Row="3"
                       Grid.Column="0"
                       Grid.ColumnSpan="3"
                       Margin="0,5,0,0"
                       HorizontalAlignment="Stretch" />
            <Button Grid.Row="4"
                    Grid.Column="2"
                    Margin="5"
                    Command="{Binding CloseApplicationCommand}"
                    Content="Close">
                <Button.ToolTip>
                    <ToolTip Content="Press to close the application." Style="{StaticResource GenericToolTipStyle}" />
                </Button.ToolTip>
            </Button>

        </Grid>
        <Border Grid.Row="0"
                Grid.Column="0"
                Background="White"
                Opacity="0.5"
                Visibility="{Binding IsBusy,
                                     Converter={StaticResource BooleanToVisibilityConverter}}">
            <controls:ProgressRing IsActive="{Binding IsBusy}" />
        </Border>
    </Grid>


</controls:MetroWindow>